package com.tyc;

import java.util.concurrent.TimeUnit;

/**
 * 用于支持完成支持性工作
 * 当虚拟机中不存在非Daemon线程 虚拟机退出
 */
public class Daemon {
    public static void main(String[] args) {
        Thread thread = new Thread(new Runner());
        thread.setDaemon(true);
        thread.start();
    }

    static class Runner implements Runnable{
        @Override
        public void run() {
            try {
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                System.out.println("DaemonThread finally run");  //这里不会执行
            }
        }
    }
}
